package com.shop2cn.iapi.sqdistributor.service;

import org.json.JSONObject;

import com.shop2cn.iapi.sqdistributor.parameter.response.GetDistributionAgencyListResponse;

import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

public class GetDistributionAgencyListCall extends YmatouBaseCall {
	private static String opurl = "/api/getDistributionAgencyList";

	public GetDistributionAgencyListCall() {
		super(EnvSetup.getSystemUrl("sqdistributor_iapi"), opurl, "POST", "JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public Integer getErrorCode() {
		Integer BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getInt("errorCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("errorMessage");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}
	
	/**
	 * 获取success
	 * 
	 * @return
	 */
	public Boolean getSuccess() {
		Boolean success = null;
		try {
			success = new JSONObject(getReturnData()).getBoolean("success");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return success;
	}

	public GetDistributionAgencyListResponse getDistributionAgencyListResponse()
			throws Exception {
		
		Object result = new JSONObject(getReturnData()).get("result");
		
		if (result.toString().equalsIgnoreCase("null"))
			return null;
		else
			return (GetDistributionAgencyListResponse) FormatUtil.GSONToObject(
					new JSONObject(getReturnData()).getJSONObject("result")
							.toString(), GetDistributionAgencyListResponse.class);
	}
}